@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>排班管理</title>
    <link href="~/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <style>
        .calendar-container {
            padding: 15px;
            display: flex;
            flex-direction: column;
        }
        .nav-tabs {
            display: flex;
            border-bottom: 1px solid #e6e6e6;
            margin-bottom: 15px;
        }
        .nav-tabs .tab-item {
            padding: 8px 16px;
            cursor: pointer;
            color: #666;
            position: relative;
        }
        .nav-tabs .tab-item.active {
            color: #1E9FFF;
        }
        .nav-tabs .tab-item.active:after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            width: 100%;
            height: 2px;
            background-color: #1E9FFF;
        }
        .main-content {
            display: flex;
            flex: 1;
        }
        .sidebar {
            width: 200px;
            background: #fff;
            padding: 15px;
            border-right: 1px solid #e6e6e6;
        }
        .sidebar-item {
            padding: 10px 15px;
            cursor: pointer;
            margin-bottom: 5px;
            border-radius: 4px;
        }
        .sidebar-item:hover {
            background: #f2f2f2;
        }
        .sidebar-item.active {
            background: #1E9FFF;
            color: #fff;
        }
        .calendar-wrapper {
            flex: 1;
            padding: 0 15px;
        }
        .calendar-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        .calendar-title {
            font-size: 16px;
            font-weight: normal;
        }
        .calendar-nav {
            display: flex;
            align-items: center;
        }
        .calendar-nav button {
            margin: 0 5px;
        }
        .calendar-grid {
            width: 100%;
            border-collapse: collapse;
        }
        .calendar-grid th {
            background: #f8f8f8;
            padding: 10px;
            text-align: center;
            border: 1px solid #e6e6e6;
        }
        .calendar-grid td {
            height: 100px;
            border: 1px solid #e6e6e6;
            padding: 8px;
            vertical-align: top;
        }
        .date-info {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
        }
        .date-number {
            font-size: 14px;
        }
        .lunar-date {
            font-size: 12px;
            color: #999;
        }
        .shift-tag {
            display: inline-block;
            padding: 2px 8px;
            background: #1E9FFF;
            color: #fff;
            border-radius: 2px;
            font-size: 12px;
            margin-top: 5px;
        }
        .shift-tag.rest {
            background: #5FB878;
        }
        .team-info {
            font-size: 12px;
            color: #5FB878;
            margin-top: 5px;
            padding: 2px 8px;
            background: #f0f9eb;
            border-radius: 2px;
            display: inline-block;
        }
        .search-box {
            margin-bottom: 15px;
        }
        .search-box input {
            width: 100%;
            padding: 8px;
            border: 1px solid #e6e6e6;
            border-radius: 4px;
        }
        .holiday {
            color: #FF5722;
        }
        .today {
            background: #f8f8f8;
        }
        .other-month {
            color: #999;
        }
    </style>
</head>
<body>
    <div class="calendar-container">
        <!-- 导航标签 -->
        <div class="nav-tabs">
            <div class="tab-item active" data-type="category">分类</div>
            <div class="tab-item" data-type="team">班组</div>
            <div class="tab-item" data-type="personal">个人</div>
        </div>

        <div class="main-content">
            <!-- 侧边栏 -->
            <div class="sidebar" id="sidebar">
                <!-- 分类模式侧边栏 -->
                <div id="category-sidebar">
                    <div class="sidebar-item active">注塑</div>
                    <div class="sidebar-item">机加工</div>
                    <div class="sidebar-item">组装</div>
                    <div class="sidebar-item">仓库</div>
                </div>
                
                <!-- 班组模式侧边栏 -->
                <div id="team-sidebar" style="display: none;">
                    <div class="sidebar-item">21</div>
                    <div class="sidebar-item">333</div>
                    <div class="sidebar-item">装配班组</div>
                    <div class="sidebar-item active">11</div>
                </div>
                
                <!-- 个人模式搜索框 -->
                <div id="personal-sidebar" style="display: none;">
                    <div class="search-box">
                        <input type="text" placeholder="人员/张作霖">
                    </div>
                </div>
            </div>

            <!-- 日历主体 -->
            <div class="calendar-wrapper">
                <div class="calendar-header">
                    <div class="calendar-title">
                        <span id="currentYearMonth">2025年6月</span>
                    </div>
                    <div class="calendar-nav">
                        <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="prevMonth()">上个月</button>
                        <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="today()">今天</button>
                        <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="nextMonth()">下个月</button>
                    </div>
                </div>

                <table class="calendar-grid">
                    <thead>
                        <tr>
                            <th>一</th>
                            <th>二</th>
                            <th>三</th>
                            <th>四</th>
                            <th>五</th>
                            <th>六</th>
                            <th>日</th>
                        </tr>
                    </thead>
                    <tbody id="calendarBody">
                        <!-- 日历内容将由JavaScript动态生成 -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="~/scripts/jquery-3.4.1.min.js"></script>
    <script src="~/scripts/layui-v2.5.6/layui/layui.js"></script>
    <script>
        layui.use(['form', 'layer'], function(){
            var form = layui.form;
            var layer = layui.layer;
            
            // 当前显示的年月
            var currentYear = 2025;
            var currentMonth = 5; // 0-11，6月
            
            // 节假日数据
            var holidays = {
                '2025-6-1': '儿童节',
                '2025-6-5': '芒种',
                '2025-6-21': '夏至',
                '2025-6-31': '端午节'
            };
            
            // 初始化日历
            initCalendar();

            // 标签切换事件
            $('.nav-tabs .tab-item').click(function() {
                var $this = $(this);
                var type = $this.data('type');
                
                // 更新标签状态
                $('.nav-tabs .tab-item').removeClass('active');
                $this.addClass('active');
                
                // 隐藏所有侧边栏内容
                $('#category-sidebar, #team-sidebar, #personal-sidebar').hide();
                
                // 显示对应的侧边栏内容
                switch(type) {
                    case 'category':
                        $('#category-sidebar').show();
                        break;
                    case 'team':
                        $('#team-sidebar').show();
                        break;
                    case 'personal':
                        $('#personal-sidebar').show();
                        break;
                }
                
                // 重新加载日历数据
                initCalendar();
            });

            // 侧边栏项目点击事件
            $('.sidebar-item').click(function() {
                var $this = $(this);
                $this.siblings().removeClass('active');
                $this.addClass('active');
                // 重新加载日历数据
                initCalendar();
            });
            
            // 初始化日历函数
            function initCalendar() {
                var firstDay = new Date(currentYear, currentMonth, 1);
                var lastDay = new Date(currentYear, currentMonth + 1, 0);
                var totalDays = lastDay.getDate();
                
                var html = '';
                var dayCount = 1;
                var totalWeeks = Math.ceil((totalDays + firstDay.getDay()) / 7);

                for (var week = 0; week < totalWeeks; week++) {
                    html += '<tr>';
                    for (var day = 0; day < 7; day++) {
                        if ((week === 0 && day < firstDay.getDay()) || dayCount > totalDays) {
                            // 空单元格
                            html += '<td></td>';
                        } else {
                            var currentDate = new Date(currentYear, currentMonth, dayCount);
                            var dateStr = formatDate(currentDate);
                            var isToday = isCurrentDay(currentDate);
                            var holiday = holidays[dateStr];
                            var lunarDate = getLunarDate(currentDate);

                            html += `
                                <td class="${isToday ? 'today' : ''}">
                                    <div class="date-info">
                                        <div>
                                            <span class="date-number ${holiday ? 'holiday' : ''}">${dayCount}</span>
                                            <span class="lunar-date">${lunarDate}</span>
                                        </div>
                                    </div>
                                    ${holiday ? `<div class="lunar-date holiday">${holiday}</div>` : ''}
                                    <div class="shift-tag">班</div>
                                    ${getActiveTab() === 'team' ? '<div class="team-info">⇢ 11</div>' : ''}
                                </td>
                            `;
                            dayCount++;
                        }
                    }
                    html += '</tr>';
                }
                
                $('#calendarBody').html(html);
                $('#currentYearMonth').text(currentYear + '年' + (currentMonth + 1) + '月');
            }
            
            // 获取当前激活的标签
            function getActiveTab() {
                return $('.nav-tabs .tab-item.active').data('type');
            }
            
            // 判断是否是当天
            function isCurrentDay(date) {
                var today = new Date();
                return date.getFullYear() === today.getFullYear() &&
                       date.getMonth() === today.getMonth() &&
                       date.getDate() === today.getDate();
            }
            
            // 格式化日期
            function formatDate(date) {
                return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            }
            
            // 获取农历日期（示例函数，实际需要农历转换算法）
            function getLunarDate(date) {
                // 这里应该使用实际的农历转换算法
                // 示例中仅返回固定值
                return '五月初一';
            }
            
            // 月份导航函数
            window.prevMonth = function() {
                currentMonth--;
                if(currentMonth < 0) {
                    currentMonth = 11;
                    currentYear--;
                }
                initCalendar();
            };
            
            window.nextMonth = function() {
                currentMonth++;
                if(currentMonth > 11) {
                    currentMonth = 0;
                    currentYear++;
                }
                initCalendar();
            };
            
            window.today = function() {
                var today = new Date();
                currentYear = today.getFullYear();
                currentMonth = today.getMonth();
                initCalendar();
            };
        });
    </script>
</body>
</html> 